﻿using System;
using System.Collections.Generic;

namespace Gmantis.Uploader
{
    public class FilePackagerPartialFile : FilePackager
    {
        public override long GetMaxSizePerUpload()
        {
            return base.MaximumUploadSize;
        }

        public override IEnumerable<UploadFilePartPackage> GetPackages()
        {
            long iteratorVariable0 = (this.MaximumUploadSize != -1L) ? this.MaximumUploadSize : 0x100000L;
            foreach (UploadFileInfo iteratorVariable1 in this.Files)
            {
                int iteratorVariable2 = 0;
                long length = iteratorVariable1.File.Length;
                int partCount = Convert.ToInt32(Math.Ceiling((double)(((double)length) / ((double)iteratorVariable0))));
                int partNumber = 1;
                while (iteratorVariable2 < length)
                {
                    long iteratorVariable6 = length - iteratorVariable2;
                    byte[] buffer = new byte[(iteratorVariable6 > iteratorVariable0) ? ((int)iteratorVariable0) : ((int)iteratorVariable6)];
                    int iteratorVariable8 = iteratorVariable1.File.Read(buffer, 0, buffer.Length);
                    iteratorVariable2 += iteratorVariable8;
                    UploadFilePartPackage iteratorVariable9 = new UploadFilePartPackage
                    {
                        ServerWaitForOneFile = true
                    };
                    iteratorVariable9.Add(new UploadFilePartInfo(iteratorVariable1.Name, buffer, partNumber, partCount));
                    partNumber++;
                    yield return iteratorVariable9;
                }
            }
        }
    }
}
